package com.fcscs.cservice.ws.endpoint;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

import com.fcscs.core.util.CommonUtil;
import com.fcscs.cservice.common.CServiceCommonEnums;
import com.fcscs.cservice.common.CServiceCommonEnums.BillOptionTypeEnum;
import com.fcscs.cservice.common.CServiceCommonEnums.ChargeBy;
import com.fcscs.cservice.common.CServiceCommonEnums.ChargeRoundingTypeEnum;
import com.fcscs.cservice.common.CServiceCommonEnums.ModuleEnum;
import com.fcscs.cservice.common.CServiceCommonEnums.PriceCategoryCodeEnum;
import com.fcscs.cservice.common.CServiceCommonEnums.VersionEntityTypeEnum;
import com.fcscs.cservice.domain.model.BillOptionView;
import com.fcscs.cservice.domain.model.CategoryView;
import com.fcscs.cservice.domain.model.ChargeCategoryTypeView;
import com.fcscs.cservice.domain.model.ChargeCategoryView;
import com.fcscs.cservice.domain.model.ChargeTypeView;
import com.fcscs.cservice.domain.model.CookOptionItemView;
import com.fcscs.cservice.domain.model.CookOptionView;
import com.fcscs.cservice.domain.model.EntityVersionView;
import com.fcscs.cservice.domain.model.ItemView;
import com.fcscs.cservice.domain.model.OrderItemChargeView;
import com.fcscs.cservice.domain.model.OrderItemView;
import com.fcscs.cservice.domain.model.OrderView;
import com.fcscs.cservice.domain.model.PriceCategoryView;
import com.fcscs.cservice.domain.model.SpicyView;
import com.fcscs.cservice.domain.model.TransactionTypeView;
import com.fcscs.cservice.domain.model.VersionView;
import com.fcscs.cservice.ws.WebServiceUtils;
import com.fcscs.cservice.ws.schema.inroomservice.CalculateOrderRequest;
import com.fcscs.cservice.ws.schema.inroomservice.CalculateOrderResponse;
import com.fcscs.cservice.ws.schema.inroomservice.CreateOrderRequest;
import com.fcscs.cservice.ws.schema.inroomservice.CreateOrderResponse;
import com.fcscs.cservice.ws.schema.inroomservice.FindItemsRequest;
import com.fcscs.cservice.ws.schema.inroomservice.FindItemsResponse;
import com.fcscs.cservice.ws.schema.inroomservice.GetBillOptionsRequest;
import com.fcscs.cservice.ws.schema.inroomservice.GetBillOptionsResponse;
import com.fcscs.cservice.ws.schema.inroomservice.GetCategoriesRequest;
import com.fcscs.cservice.ws.schema.inroomservice.GetCategoriesResponse;
import com.fcscs.cservice.ws.schema.inroomservice.GetChargeCategoriesRequest;
import com.fcscs.cservice.ws.schema.inroomservice.GetChargeCategoriesResponse;
import com.fcscs.cservice.ws.schema.inroomservice.GetCookOptionsRequest;
import com.fcscs.cservice.ws.schema.inroomservice.GetCookOptionsResponse;
import com.fcscs.cservice.ws.schema.inroomservice.GetEntityVersionViewRequest;
import com.fcscs.cservice.ws.schema.inroomservice.GetEntityVersionViewResponse;
import com.fcscs.cservice.ws.schema.inroomservice.GetItemsRequest;
import com.fcscs.cservice.ws.schema.inroomservice.GetItemsResponse;
import com.fcscs.cservice.ws.schema.inroomservice.GetSpiciesRequest;
import com.fcscs.cservice.ws.schema.inroomservice.GetSpiciesResponse;
import com.fcscs.cservice.ws.schema.inroomservice.GetVersionsRequest;
import com.fcscs.cservice.ws.schema.inroomservice.GetVersionsResponse;
import com.fcscs.share.domain.nonexport.WsSession;
import com.fcscs.share.service.WsSessionManager;
import com.fcscs.share.util.TimezoneUtils;

@Endpoint
public class InRoomServiceEndpoint {

	@Autowired
	private WsSessionManager ssMgr;

	private int calOrderCharges(OrderView orderView) {
		List<OrderItemView> list = orderView.getOrderItemList();
		double amount = 0;
		int leadTime = 0;
		if (list != null) {
			for (int i = 0; i < list.size(); ++i) {
				OrderItemView oi = list.get(i);
				oi.setOrderId(1L);
				oi.setOrderItemId((long)i);
				double itemCharge = oi.getQuantity() * prices[(int) oi.getItemId()];
				leadTime = leadTime >= leadTimes[(int) oi.getItemId()] ? leadTime : leadTimes[(int) oi.getItemId()];
				List<OrderItemChargeView> oicvList = new ArrayList<OrderItemChargeView>();
				OrderItemChargeView oicv1 = new OrderItemChargeView();
				oicv1.setOrderItemId((long)i);
				oicv1.setOrderItemChargeId((long)i * 2);
				oicv1.setChargeCategoryId(2L);
				oicv1.setChargeCategoryTypeId(2L);
				oicv1.setChargeTypeId(1L);
				oicv1.setChargeType("Service Charge");
				oicv1.setChargeTypeCode("SRVCH");
				oicv1.setAmount(10.0);
				oicvList.add(oicv1);
				OrderItemChargeView oicv2 = new OrderItemChargeView();
				oicv2.setOrderItemId((long)i);
				oicv2.setOrderItemChargeId((long)i * 2 + 1);
				oicv2.setChargeCategoryId(4L);
				oicv2.setChargeCategoryTypeId(4L);
				oicv2.setChargeTypeId(3L);
				oicv2.setChargeType("Tax");
				oicv2.setChargeTypeCode("TAXCH");
				oicv2.setAmount(itemCharge * 0.1);
				oicvList.add(oicv2);
				oi.setOrderItemChargeViewList(oicvList);
				itemCharge = itemCharge + oicv1.getAmount() + oicv2.getAmount();
				oi.setAmount(itemCharge);
				amount += itemCharge;
			}
		}
		Calendar c = Calendar.getInstance();
		c.add(Calendar.MINUTE, leadTime);
		Date delivTime = c.getTime();
		orderView.setOrderId(1L);
		orderView.setAmount(amount);
		if (orderView.getDeliveryTime().before(delivTime)) {
			orderView.setDeliveryTime(delivTime);
		}
		return leadTime;
	}

	@PayloadRoot(localPart = CServiceWSConstants.CAL_ORDER_REQ, namespace = CServiceWSConstants.INROOM_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public CalculateOrderResponse calOrder(@RequestPayload CalculateOrderRequest req) {
		CalculateOrderResponse resp = new CalculateOrderResponse();
		OrderView orderView = req.getOrderView();
		int leadTime = calOrderCharges(orderView);
		resp.setLeadTime(leadTime);
		resp.setOrderView(orderView);
		return resp;
	}

	@PayloadRoot(localPart = CServiceWSConstants.CREATE_ORDER_REQ, namespace = CServiceWSConstants.INROOM_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public CreateOrderResponse createOrder(@RequestPayload CreateOrderRequest req) {
		CreateOrderResponse resp = new CreateOrderResponse();
		OrderView orderView = req.getOrderView();
		Long userId = CommonUtil.getWsSessionUserId();
		if (userId != null) {
			WsSession ss = ssMgr.getSession(userId);
			if (ss != null) {
				orderView.setSourceEnum(ss.getSourceEnum());
			}
		}
		calOrderCharges(orderView);
		resp.setOrderView(orderView);
		return resp;
	}

	@PayloadRoot(localPart = CServiceWSConstants.FIND_ITEMS_REQ, namespace = CServiceWSConstants.INROOM_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public FindItemsResponse findItems(@RequestPayload FindItemsRequest req) {
		FindItemsResponse resp = new FindItemsResponse();

		EntityVersionView cmv5 = new EntityVersionView();
		cmv5.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		cmv5.setDescription(VersionEntityTypeEnum.CATEGORY.getDisplayStr());
		VersionView vv5 = new VersionView();
		vv5.setEntityType(VersionEntityTypeEnum.CATEGORY.toString());
		vv5.setEntityId(5L);
		vv5.setVersion(1L);
		cmv5.setVersionView(vv5);
		cmv5.setEntityVersionList(dummyItemVersionViewList());
		List<EntityVersionView> subCatMenuList = new ArrayList<EntityVersionView>();
		subCatMenuList.add(cmv5);
		resp.setEntityVersionList(subCatMenuList);
		return resp;
	}

	private List<EntityVersionView> dummyItemVersionViewList() {
		VersionView vv1 = new VersionView();
		vv1.setEntityId(1L);
		vv1.setEntityType(VersionEntityTypeEnum.ITEM.toString());
		vv1.setVersion(1L);
		EntityVersionView evv1 = new EntityVersionView();
		evv1.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		evv1.setDescription(VersionEntityTypeEnum.ITEM.getDisplayStr());
		evv1.setVersionView(vv1);
		
		VersionView vv2 = new VersionView();
		vv2.setEntityId(2L);
		vv2.setEntityType(VersionEntityTypeEnum.ITEM.toString());
		vv2.setVersion(2L);
		EntityVersionView evv2 = new EntityVersionView();
		evv2.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		evv2.setDescription(VersionEntityTypeEnum.ITEM.getDisplayStr());
		evv2.setVersionView(vv2);
		
		VersionView vv3 = new VersionView();
		vv3.setEntityId(3L);
		vv3.setEntityType(VersionEntityTypeEnum.ITEM.toString());
		vv3.setVersion(3L);
		EntityVersionView evv3 = new EntityVersionView();
		evv3.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		evv3.setDescription(VersionEntityTypeEnum.ITEM.getDisplayStr());
		evv3.setVersionView(vv3);
		
		VersionView vv4 = new VersionView();
		vv4.setEntityId(4L);
		vv4.setEntityType(VersionEntityTypeEnum.ITEM.toString());
		vv4.setVersion(4L);
		EntityVersionView evv4 = new EntityVersionView();
		evv4.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		evv4.setDescription(VersionEntityTypeEnum.ITEM.getDisplayStr());
		evv4.setVersionView(vv4);
		
		VersionView vv5 = new VersionView();
		vv5.setEntityId(5L);
		vv5.setEntityType(VersionEntityTypeEnum.ITEM.toString());
		vv5.setVersion(6L);
		EntityVersionView evv5 = new EntityVersionView();
		evv5.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		evv5.setDescription(VersionEntityTypeEnum.ITEM.getDisplayStr());
		evv5.setVersionView(vv5);
		
		VersionView vv6 = new VersionView();
		vv6.setEntityId(6L);
		vv6.setEntityType(VersionEntityTypeEnum.ITEM.toString());
		vv6.setVersion(1L);
		EntityVersionView evv6 = new EntityVersionView();
		evv6.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		evv6.setDescription(VersionEntityTypeEnum.ITEM.getDisplayStr());
		evv6.setVersionView(vv6);

		List<EntityVersionView> list = new ArrayList<EntityVersionView>(6);
		list.add(evv1);
		list.add(evv2);
		list.add(evv3);
		list.add(evv4);
		list.add(evv5);
		list.add(evv6);
		return list;
	}

	private List<EntityVersionView> dummyOtherVersionViewList() {
		VersionView vv1 = new VersionView();
		vv1.setEntityId(null);
		vv1.setEntityType(VersionEntityTypeEnum.ADVERTISEMENT.toString());
		vv1.setVersion(8L);
		EntityVersionView evv1 = new EntityVersionView();
		evv1.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		evv1.setDescription(VersionEntityTypeEnum.ADVERTISEMENT.getDisplayStr());
		evv1.setVersionView(vv1);

		VersionView vv2 = new VersionView();
		vv2.setEntityId(null);
		vv2.setEntityType(VersionEntityTypeEnum.COOK_OPTION.toString());
		vv2.setVersion(12L);
		EntityVersionView evv2 = new EntityVersionView();
		evv2.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		evv2.setDescription(VersionEntityTypeEnum.COOK_OPTION.getDisplayStr());
		evv2.setVersionView(vv1);

		VersionView vv3 = new VersionView();
		vv3.setEntityId(null);
		vv3.setEntityType(VersionEntityTypeEnum.MAIN_MENU.toString());
		vv3.setVersion(3L);
		EntityVersionView evv3 = new EntityVersionView();
		evv3.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		evv3.setDescription(VersionEntityTypeEnum.MAIN_MENU.getDisplayStr());
		evv3.setVersionView(vv3);

		VersionView vv4 = new VersionView();
		vv4.setEntityId(null);
		vv4.setEntityType(VersionEntityTypeEnum.THEME.toString());
		vv4.setVersion(4L);
		EntityVersionView evv4 = new EntityVersionView();
		evv4.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		evv4.setDescription(VersionEntityTypeEnum.THEME.getDisplayStr());
		evv4.setVersionView(vv4);

		List<EntityVersionView> list = new ArrayList<EntityVersionView>(4);
		list.add(evv1);
		list.add(evv2);
		list.add(evv3);
		list.add(evv4);
		return list;
	}

	@PayloadRoot(localPart = CServiceWSConstants.GET_CATS_REQ, namespace = CServiceWSConstants.INROOM_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public GetCategoriesResponse getCategories(@RequestPayload GetCategoriesRequest req) {
		GetCategoriesResponse resp = new GetCategoriesResponse();
		if (req.getParentCategoryId() == null) {
			CategoryView cv1 = new CategoryView();
			cv1.setCategoryId(1L);
			cv1.setName("All Day");
			cv1.setFromTime(TimezoneUtils.convertForSendWSTime(Time.valueOf("00:00:00"), null));
			cv1.setToTime(TimezoneUtils.convertForSendWSTime(Time.valueOf("23:59:59"), null));
			cv1.setDescription("All day food");
			cv1.setVersion(1);
			CategoryView cv2 = new CategoryView();
			cv2.setCategoryId(2L);
			cv2.setName("Breakfast");
			cv2.setFromTime(TimezoneUtils.convertForSendWSTime(Time.valueOf("06:30:00"), null));
			cv2.setToTime(TimezoneUtils.convertForSendWSTime(Time.valueOf("11:00:00"), null));
			cv2.setDescription("Breakfast");
			cv2.setVersion(1);
			CategoryView cv3 = new CategoryView();
			cv3.setCategoryId(3L);
			cv3.setName("Lunch");
			cv3.setFromTime(TimezoneUtils.convertForSendWSTime(Time.valueOf("11:00:00"), null));
			cv3.setToTime(TimezoneUtils.convertForSendWSTime(Time.valueOf("16:30:30"), null));
			cv3.setDescription("Lunch");
			cv3.setVersion(1);
			CategoryView cv4 = new CategoryView();
			cv4.setCategoryId(4L);
			cv4.setName("Dinner");
			cv4.setFromTime(TimezoneUtils.convertForSendWSTime(Time.valueOf("16:30:00"), null));
			cv4.setToTime(TimezoneUtils.convertForSendWSTime(Time.valueOf("22:00:00"), null));
			cv4.setDescription("Dinner");
			cv4.setVersion(1);
			List<CategoryView> list = new ArrayList<CategoryView>(4);
			list.add(cv1);
			list.add(cv2);
			list.add(cv3);
			list.add(cv4);
			resp.setCategoryList(list);
		} else {
			CategoryView cv1 = new CategoryView();
			cv1.setCategoryId(5L);
			cv1.setName("Main Course");
			cv1.setFromTime(TimezoneUtils.convertForSendWSTime(Time.valueOf("00:00:00"), null));
			cv1.setToTime(TimezoneUtils.convertForSendWSTime(Time.valueOf("23:59:59"), null));
			cv1.setDescription("Main course");
			cv1.setPriceCategoryCode(PriceCategoryCodeEnum.P1.toString());
			CategoryView cv2 = new CategoryView();
			cv2.setCategoryId(6L);
			cv2.setName("Appetizer");
			cv2.setFromTime(TimezoneUtils.convertForSendWSTime(Time.valueOf("00:00:00"), null));
			cv2.setToTime(TimezoneUtils.convertForSendWSTime(Time.valueOf("23:59:59"), null));
			cv2.setDescription("Appetizer");
			cv2.setPriceCategoryCode(PriceCategoryCodeEnum.P2.toString());
			CategoryView cv3 = new CategoryView();
			cv3.setCategoryId(7L);
			cv3.setName("Dessert");
			cv3.setFromTime(TimezoneUtils.convertForSendWSTime(Time.valueOf("00:00:00"), null));
			cv3.setToTime(TimezoneUtils.convertForSendWSTime(Time.valueOf("23:59:59"), null));
			cv3.setDescription("Dessert");
			cv3.setPriceCategoryCode(PriceCategoryCodeEnum.P3.toString());
			List<CategoryView> list = new ArrayList<CategoryView>(4);
			list.add(cv1);
			list.add(cv2);
			list.add(cv3);
			resp.setCategoryList(list);
		}
		return resp;
	}

	@PayloadRoot(localPart = CServiceWSConstants.GET_COPTIONS_REQ, namespace = CServiceWSConstants.INROOM_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public GetCookOptionsResponse getCookOptions(@RequestPayload GetCookOptionsRequest req) {
		GetCookOptionsResponse resp = new GetCookOptionsResponse();
		CookOptionItemView coi1 = new CookOptionItemView();
		coi1.setOptionItemId(1L);
		coi1.setItem("Rare");
		CookOptionItemView coi2 = new CookOptionItemView();
		coi2.setOptionItemId(2L);
		coi2.setItem("Medium Rare");
		CookOptionItemView coi3 = new CookOptionItemView();
		coi3.setOptionItemId(3L);
		coi3.setItem("Medium");
		CookOptionItemView coi4 = new CookOptionItemView();
		coi4.setOptionItemId(4L);
		coi4.setItem("Well Done");
		CookOptionItemView coi5 = new CookOptionItemView();
		coi5.setOptionItemId(5L);
		coi5.setItem("Boiled egg");
		CookOptionItemView coi6 = new CookOptionItemView();
		coi6.setOptionItemId(6L);
		coi6.setItem("Fried egg");
		List<CookOptionItemView> coiList = new ArrayList<CookOptionItemView>(6);
		coiList.add(coi1);
		coiList.add(coi2);
		coiList.add(coi3);
		coiList.add(coi4);
		coiList.add(coi5);
		coiList.add(coi6);
		resp.setCookOptionItemList(coiList);
		return resp;
	}

	private List<PriceCategoryView> dummyPriceCategoryList(long itemId) {
		List<PriceCategoryView> pcvList = new ArrayList<PriceCategoryView>(3);
		PriceCategoryView p1 = new PriceCategoryView();
		p1.setItemId(itemId);
		p1.setPriceCategoryCode(PriceCategoryCodeEnum.P1.toString());
		p1.setPrice(prices[(int)itemId]);
		pcvList.add(p1);
		PriceCategoryView p2 = new PriceCategoryView();
		p2.setItemId(itemId);
		p2.setPriceCategoryCode(PriceCategoryCodeEnum.P2.toString());
		p2.setPrice(prices[(int)itemId] + 10);
		pcvList.add(p2);
		PriceCategoryView p3 = new PriceCategoryView();
		p3.setItemId(itemId);
		p3.setPriceCategoryCode(PriceCategoryCodeEnum.P3.toString());
		p3.setPrice(prices[(int)itemId] + 20);
		pcvList.add(p3);
		return pcvList;
	}

	private List<CookOptionView> dummyCookOptionList(int optionId) {
		List<CookOptionView> covList = new ArrayList<CookOptionView>(2);
		if (optionId == 1) {
			CookOptionView cov1 = new CookOptionView();
			cov1.setOption("Cook Option1");
			cov1.setOptionId(1L);
			List<Long> coiList1 = new ArrayList<Long>(4);
			coiList1.add(1L);
			coiList1.add(2L);
			coiList1.add(3L);
			coiList1.add(4L);
			cov1.setOptionItemList(coiList1);
			covList.add(cov1);
		} else {
			CookOptionView cov2 = new CookOptionView();
			cov2.setOption("Cook Option2");
			cov2.setOptionId(2L);
			List<Long> coiList2 = new ArrayList<Long>(2);
			coiList2.add(5L);
			coiList2.add(6L);
			cov2.setOptionItemList(coiList2);
			covList.add(cov2);
		}
		return covList;
	}
	
	@PayloadRoot(localPart = CServiceWSConstants.GET_ITEMS_REQ, namespace = CServiceWSConstants.INROOM_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public GetItemsResponse getItems(@RequestPayload GetItemsRequest req) {
		GetItemsResponse resp = new GetItemsResponse();
		List<Long> coIdList = new ArrayList<Long>(1);
		coIdList.add(1L);
		List<Long> spicyIdList = new ArrayList<Long>(1);
		spicyIdList.add(1L);

		ItemView iv1 = new ItemView();
		iv1.setItemId(1L);
		iv1.setFromTime(createDate(0, 0, 0, 0, 0, 0));
		iv1.setToTime(createDate(0, 0, 0, 23, 59, 59));
		iv1.setName("Ceasar Salad");
		iv1.setDescription("凱撒沙律");
		iv1.setDetail("Caesar Salad");
		iv1.setPriceCategoryViewList(dummyPriceCategoryList(1L));
		iv1.setLeadTime(leadTimes[1]);
		iv1.setChargeCategoryId(1L);
		iv1.setTransactionTypeId(1L);
		iv1.setVersion(1L);
		iv1.setSpicyIdList(spicyIdList);
		ItemView iv2 = new ItemView();
		iv2.setItemId(2L);
		iv2.setFromTime(createDate(0, 0, 0, 0, 0, 0));
		iv2.setToTime(createDate(0, 0, 0, 23, 59, 59));
		iv2.setName("U.S. Top Sirioin Steak");
		iv2.setDescription("美國頂級沙朗牛排");
		iv2.setDetail("U.S. Top Sirioin Steak");
		iv2.setPriceCategoryViewList(dummyPriceCategoryList(2L));
		iv2.setLeadTime(leadTimes[2]);
		iv2.setChargeCategoryId(1L);
		iv2.setTransactionTypeId(1L);
		iv2.setCookOptionList(dummyCookOptionList(1));
		iv2.setVersion(1L);
		ItemView iv3 = new ItemView();
		iv3.setItemId(3L);
		iv3.setFromTime(createDate(0, 0, 0, 0, 0, 0));
		iv3.setToTime(createDate(0, 0, 0, 23, 59, 59));
		iv3.setName("Roast GermanPig Feet with Sour Cabbage");
		iv3.setDescription("烤德國豬腳佐酸菜");
		iv3.setDetail("Roast GermanPig Feet with Sour Cabbage");
		iv3.setPriceCategoryViewList(dummyPriceCategoryList(3L));
		iv3.setLeadTime(leadTimes[3]);
		iv3.setChargeCategoryId(1L);
		iv3.setTransactionTypeId(1L);
		iv3.setVersion(1L);
		ItemView iv4 = new ItemView();
		iv4.setItemId(4L);
		iv4.setFromTime(createDate(0, 0, 0, 0, 0, 0));
		iv4.setToTime(createDate(0, 0, 0, 23, 59, 59));
		iv4.setName("Comprehensive Seafood Baked Rice");
		iv4.setDescription("綜合海鮮焗飯");
		iv4.setDetail("Comprehensive Seafood Baked Rice");
		iv4.setPriceCategoryViewList(dummyPriceCategoryList(4L));
		iv4.setLeadTime(leadTimes[4]);
		iv4.setChargeCategoryId(1L);
		iv4.setTransactionTypeId(1L);
		iv4.setVersion(1L);
		ItemView iv5 = new ItemView();
		iv5.setItemId(5L);
		iv5.setFromTime(createDate(0, 0, 0, 0, 0, 0));
		iv5.setToTime(createDate(0, 0, 0, 23, 59, 59));
		iv5.setName("Man Dill Salmon Sushi");
		iv5.setDescription("蘿蔓鮭魚壽司");
		iv5.setDetail("Man Dill Salmon Sushi");
		iv5.setPriceCategoryViewList(dummyPriceCategoryList(5L));
		iv5.setLeadTime(leadTimes[5]);
		iv5.setChargeCategoryId(1L);
		iv5.setTransactionTypeId(1L);
		iv5.setCookOptionList(dummyCookOptionList(2));
		iv5.setVersion(1L);
		ItemView iv6 = new ItemView();
		iv6.setItemId(6L);
		iv6.setFromTime(createDate(0, 0, 0, 0, 0, 0));
		iv6.setToTime(createDate(0, 0, 0, 23, 59, 59));
		iv6.setName("Lemon Salt Baked Sweet Prawn");
		iv6.setDescription("檸香鹽烤明蝦");
		iv6.setDetail("Lemon Salt Baked Sweet Prawn");
		iv6.setPriceCategoryViewList(dummyPriceCategoryList(6L));
		iv6.setLeadTime(leadTimes[6]);
		iv6.setChargeCategoryId(1L);
		iv6.setTransactionTypeId(1L);
		iv6.setCookOptionList(dummyCookOptionList(1));
		iv6.setVersion(1L);
		iv6.setSpicyIdList(spicyIdList);

		List<ItemView> list = new ArrayList<ItemView>(6);
		list.add(iv1);
		list.add(iv2);
		list.add(iv3);
		list.add(iv4);
		list.add(iv5);
		list.add(iv6);
		resp.setItemList(list);
		return resp;
	}

	@PayloadRoot(localPart = CServiceWSConstants.GET_VERSIONS_REQ, namespace = CServiceWSConstants.INROOM_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public GetVersionsResponse getVersions(@RequestPayload GetVersionsRequest req) {
		GetVersionsResponse resp = new GetVersionsResponse();
		VersionView vv1 = new VersionView();
		vv1.setEntityId(1L);
		vv1.setEntityType(CServiceCommonEnums.VersionEntityTypeEnum.CATEGORY.toString());
		vv1.setVersion(1L);
		VersionView vv2 = new VersionView();
		vv2.setEntityId(1L);
		vv2.setEntityType(CServiceCommonEnums.VersionEntityTypeEnum.CATEGORY.toString());
		vv2.setVersion(3L);
		VersionView vv3 = new VersionView();
		vv3.setEntityId(1L);
		vv3.setEntityType(CServiceCommonEnums.VersionEntityTypeEnum.ITEM.toString());
		vv3.setVersion(2L);
		VersionView vv4 = new VersionView();
		vv4.setEntityId(5L);
		vv4.setEntityType(CServiceCommonEnums.VersionEntityTypeEnum.CATEGORY.toString());
		vv4.setVersion(4L);
		VersionView vv5 = new VersionView();
		vv5.setEntityId(3L);
		vv5.setEntityType(CServiceCommonEnums.VersionEntityTypeEnum.ITEM.toString());
		vv5.setVersion(2L);
		List<VersionView> list = new ArrayList<VersionView>(6);
		list.add(vv1);
		list.add(vv2);
		list.add(vv3);
		list.add(vv4);
		list.add(vv5);
		resp.setVersionList(list);
		return resp;
	}

	@PayloadRoot(localPart = CServiceWSConstants.GET_BILL_OPTION_REQ, namespace = CServiceWSConstants.INROOM_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public GetBillOptionsResponse getBillOptions(@RequestPayload GetBillOptionsRequest req) {
		GetBillOptionsResponse resp = new GetBillOptionsResponse();
		List<BillOptionView> list = new ArrayList<BillOptionView>();
		long id = 1L;
		for (BillOptionTypeEnum t : BillOptionTypeEnum.values()) {
			BillOptionView b1 = new BillOptionView();
			b1.setBillOptionId(id++);
			if (!BillOptionTypeEnum.OTHER.equals(t)) {
				b1.setName(t.getDisplayStr());
				b1.setType(t.toString());
				b1.setCode(t.toString());
			} else {
				b1.setName("Alipay");
				b1.setType(BillOptionTypeEnum.OTHER.toString());
				b1.setCode("Alipay");
			}
			list.add(b1);
		}
		resp.setBillOptionList(list);
		return resp;
	}

	private List<TransactionTypeView> dummyTransactionTypeList() {
		List<TransactionTypeView> txList = new ArrayList<TransactionTypeView>();
		TransactionTypeView txv1 = new TransactionTypeView();
		txv1.setTransactionTypeId(1L);
		txv1.setName("Food");
		txv1.setCode("FOOD");
		txv1.setIsRevenue(true);
		txList.add(txv1);
		TransactionTypeView txv2 = new TransactionTypeView();
		txv2.setTransactionTypeId(2L);
		txv2.setName("Service");
		txv2.setCode("SERV");
		txv2.setIsRevenue(true);
		txList.add(txv2);
		TransactionTypeView txv3 = new TransactionTypeView();
		txv3.setTransactionTypeId(3L);
		txv3.setName("Tax");
		txv3.setCode("TAX");
		txv3.setIsRevenue(false);
		txList.add(txv3);
		return txList;
	}

	private List<ChargeTypeView> dummyChargeTypeList() {
		List<ChargeTypeView> chList = new ArrayList<ChargeTypeView>();
		ChargeTypeView ch1 = new ChargeTypeView();
		ch1.setChargeTypeId(1L);
		ch1.setName("Service Charge");
		ch1.setCode("SRVCH");
		ch1.setTransactionTypeId(2L);
		ch1.setTransactionTypeCode("SRV");
		ch1.setIsServiceType(true);
		chList.add(ch1);
		ChargeTypeView ch2 = new ChargeTypeView();
		ch2.setChargeTypeId(2L);
		ch2.setName("Delivery Charge");
		ch2.setCode("DLVCH");
		ch2.setTransactionTypeId(2L);
		ch2.setTransactionTypeCode("SRV");
		ch2.setIsServiceType(true);
		chList.add(ch2);
		ChargeTypeView ch3 = new ChargeTypeView();
		ch3.setChargeTypeId(3L);
		ch3.setName("Tax");
		ch3.setCode("TAXCH");
		ch3.setTransactionTypeId(3L);
		ch3.setTransactionTypeCode("TAX");
		ch3.setIsServiceType(false);
		chList.add(ch3);
		ChargeTypeView ch4 = new ChargeTypeView();
		ch4.setChargeTypeId(4L);
		ch4.setName("VAT");
		ch4.setCode("VATCH");
		ch4.setTransactionTypeId(3L);
		ch4.setTransactionTypeCode("TAX");
		ch4.setIsServiceType(false);
		chList.add(ch4);
		return chList;
	}

	private List<ChargeCategoryTypeView> dummyChargeCategoryTypeList() {
		List<ChargeCategoryTypeView> ctList = new ArrayList<ChargeCategoryTypeView>();
		ChargeCategoryTypeView ctv1 = new ChargeCategoryTypeView();
		ctv1.setChargeCategoryTypeId(2L);
		ctv1.setChargeTypeId(1L);
		ctv1.setChargeTypeCode("SRVCH");
		ctv1.setTransactionTypeId(2L);
		ctv1.setTransactionTypeCode("SERV");
		ctv1.setChargeByType(ChargeBy.FIXED.toString());
		ctv1.setValue(BigDecimal.valueOf(10.0));
//		ctv1.setCode("S01");
		ctList.add(ctv1);
		ChargeCategoryTypeView ctv2 = new ChargeCategoryTypeView();
		ctv2.setChargeCategoryTypeId(3L);
		ctv2.setChargeTypeId(2L);
		ctv2.setChargeTypeCode("DLVCH");
		ctv2.setTransactionTypeId(2L);
		ctv2.setTransactionTypeCode("SERV");
		ctv2.setChargeByType(ChargeBy.PERCENTAGE.toString());
		ctv2.setValue(BigDecimal.valueOf(10.0));
//		ctv2.setCode("S01");
		ctList.add(ctv2);
		ChargeCategoryTypeView ctv3 = new ChargeCategoryTypeView();
		ctv3.setChargeCategoryTypeId(4L);
		ctv3.setChargeTypeId(3L);
		ctv3.setChargeTypeCode("TAXCH");
		ctv3.setTransactionTypeId(3L);
		ctv3.setTransactionTypeCode("TAX");
		ctv3.setChargeByType(ChargeBy.FIXED.toString());
		ctv3.setValue(BigDecimal.valueOf(10.0));
//		ctv3.setCode("T11");
		ctList.add(ctv3);
		ChargeCategoryTypeView ctv4 = new ChargeCategoryTypeView();
		ctv4.setChargeCategoryTypeId(5L);
		ctv4.setChargeTypeId(4L);
		ctv4.setChargeTypeCode("VATCH");
		ctv4.setTransactionTypeId(3L);
		ctv4.setTransactionTypeCode("TAX");
		ctv4.setChargeByType(ChargeBy.PERCENTAGE.toString());
		ctv4.setValue(BigDecimal.valueOf(10.0));
//		ctv4.setCode("T12");
		ctList.add(ctv4);
		return ctList;
	}

	@PayloadRoot(localPart = CServiceWSConstants.GET_CHARGE_CATS_REQ, namespace = CServiceWSConstants.INROOM_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public GetChargeCategoriesResponse getChargeCategories(@RequestPayload GetChargeCategoriesRequest req) {

		GetChargeCategoriesResponse resp = new GetChargeCategoriesResponse();
		resp.setTransactionTypeViewList(dummyTransactionTypeList());
		resp.setChargeTypeViewList(dummyChargeTypeList());
		resp.setDecimalPlaces(2);
		resp.setRounding(ChargeRoundingTypeEnum.UP.toString());

		ChargeCategoryView globalCC = new ChargeCategoryView();
		globalCC.setChargeCategoryId(1L);
		globalCC.setName("Delivery Charge (per order)");
		globalCC.setCode("GDLVCH");
		List<ChargeCategoryTypeView> gctList = new ArrayList<ChargeCategoryTypeView>();
		ChargeCategoryTypeView gctv = new ChargeCategoryTypeView();
		gctv.setChargeCategoryTypeId(1L);
		gctv.setChargeTypeId(2L);
		gctv.setChargeTypeCode("DLVCH");
		gctv.setTransactionTypeId(2L);
		gctv.setTransactionTypeCode("SERV");
		gctv.setChargeByType(ChargeBy.FIXED.toString());
		gctv.setValue(BigDecimal.valueOf(10.0));
		gctList.add(gctv);
		globalCC.setChargeCategoryTypeList(gctList);
		resp.setPerOrderChargeCategoryView(globalCC);
		
		List<ChargeCategoryView> ccvList = new ArrayList<ChargeCategoryView>();
		ChargeCategoryView ccv1 = new ChargeCategoryView();
		ccv1.setChargeCategoryId(1L);
		ccv1.setChargeCategoryTypeList(dummyChargeCategoryTypeList());
		ccv1.setCode("FOOD");
		ccv1.setName("Food");
		ccvList.add(ccv1);
		ChargeCategoryView ccv2 = new ChargeCategoryView();
		ccv2.setChargeCategoryId(2L);
		ccv2.setChargeCategoryTypeList(dummyChargeCategoryTypeList());
		ccv2.setCode("BEVR");
		ccv2.setName("Beverage");
		ccvList.add(ccv2);
		ChargeCategoryView ccv3 = new ChargeCategoryView();
		ccv3.setChargeCategoryId(3L);
		ccv3.setChargeCategoryTypeList(dummyChargeCategoryTypeList());
		ccv3.setCode("ALCO");
		ccv3.setName("Alcoholic");
		ccvList.add(ccv3);
		ChargeCategoryView ccv4 = new ChargeCategoryView();
		ccv4.setChargeCategoryId(4L);
		ccv4.setChargeCategoryTypeList(dummyChargeCategoryTypeList());
		ccv4.setCode("TOBAC");
		ccv4.setName("Tobacco");
		ccvList.add(ccv4);

		resp.setChargeCategoryViewList(ccvList);
		return resp;
	}

	@Value("/dummy/menu_item_chili.png")
	Resource dummySpicy;

	@PayloadRoot(localPart = CServiceWSConstants.GET_SPICIES_REQ, namespace = CServiceWSConstants.INROOM_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public GetSpiciesResponse getSpicies(@RequestPayload GetSpiciesRequest req) {

		FileInputStream fin = null;
		byte[] fileContent = null;
		try {
			fin = new FileInputStream(dummySpicy.getFile());
			fileContent = new byte[(int) dummySpicy.getFile().length()];
			fin.read(fileContent);
			fin.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		GetSpiciesResponse resp = new GetSpiciesResponse();
		List<SpicyView> list = new ArrayList<SpicyView>();
		SpicyView sp = new SpicyView();
		sp.setIconFile(WebServiceUtils.convertToString(fileContent));
		sp.setName("Spicy");
		sp.setSpicyId(1L);
		list.add(sp);
		resp.setSpicyList(list);
		return resp;
	}

	private static Date createDate(int year, int month, int day, int hour, int minute, int second) {
		Calendar c = Calendar.getInstance();
		c.set(Calendar.YEAR, year);
		c.set(Calendar.MONTH, month);
		c.set(Calendar.DAY_OF_MONTH, day);
		c.set(Calendar.HOUR_OF_DAY, hour);
		c.set(Calendar.MINUTE, minute);
		c.set(Calendar.SECOND, second);
		return c.getTime();
	}
	
	private static double[] prices = new double[] { 0, 98, 189, 168, 98, 58, 128, 78, 138, 88, 198 };
	private static int[] leadTimes = new int[] { 0, 10, 30, 20, 15, 35, 25, 20, 25, 30, 20 };

	
	@PayloadRoot(localPart = CServiceWSConstants.GET_ENTITY_VER_REQ, namespace = CServiceWSConstants.INROOM_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public GetEntityVersionViewResponse getEntityVersionView(@RequestPayload GetEntityVersionViewRequest req) {
		GetEntityVersionViewResponse resp = new GetEntityVersionViewResponse();
		List<EntityVersionView> catMenuList = new ArrayList<EntityVersionView>();
		List<EntityVersionView> subCatMenuList = new ArrayList<EntityVersionView>();

		EntityVersionView cmv5 = new EntityVersionView();
		cmv5.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		cmv5.setDescription(VersionEntityTypeEnum.CATEGORY.getDisplayStr());
		VersionView vv5 = new VersionView();
		vv5.setEntityType(VersionEntityTypeEnum.CATEGORY.toString());
		vv5.setEntityId(5L);
		vv5.setVersion(1L);
		cmv5.setVersionView(vv5);
		cmv5.setEntityVersionList(dummyItemVersionViewList());
		subCatMenuList.add(cmv5);
		EntityVersionView cmv6 = new EntityVersionView();
		cmv6.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		cmv6.setDescription(VersionEntityTypeEnum.CATEGORY.getDisplayStr());
		VersionView vv6 = new VersionView();
		vv6.setEntityType(VersionEntityTypeEnum.CATEGORY.toString());
		vv6.setEntityId(6L);
		vv6.setVersion(2L);
		cmv6.setVersionView(vv6);
		cmv6.setEntityVersionList(dummyItemVersionViewList());
		subCatMenuList.add(cmv6);
		EntityVersionView cmv7 = new EntityVersionView();
		cmv7.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		cmv7.setDescription(VersionEntityTypeEnum.CATEGORY.getDisplayStr());
		VersionView vv7 = new VersionView();
		vv7.setEntityType(VersionEntityTypeEnum.CATEGORY.toString());
		vv7.setEntityId(7L);
		vv7.setVersion(3L);
		cmv7.setVersionView(vv7);
		cmv7.setEntityVersionList(dummyItemVersionViewList());
		subCatMenuList.add(cmv7);

		EntityVersionView cmv1 = new EntityVersionView();
		cmv1.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		cmv1.setDescription(VersionEntityTypeEnum.CATEGORY.getDisplayStr());
		VersionView vv1 = new VersionView();
		vv1.setEntityType(VersionEntityTypeEnum.CATEGORY.toString());
		vv1.setEntityId(1L);
		vv1.setVersion(3L);
		cmv1.setVersionView(vv1);
		cmv1.setEntityVersionList(subCatMenuList);
		catMenuList.add(cmv1);

		EntityVersionView cmv2 = new EntityVersionView();
		cmv2.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		cmv2.setDescription(VersionEntityTypeEnum.CATEGORY.getDisplayStr());
		VersionView vv2 = new VersionView();
		vv2.setEntityType(VersionEntityTypeEnum.CATEGORY.toString());
		vv2.setEntityId(2L);
		vv2.setVersion(3L);
		cmv2.setVersionView(vv2);
		cmv2.setEntityVersionList(subCatMenuList);
		catMenuList.add(cmv2);

		EntityVersionView cmv3 = new EntityVersionView();
		cmv3.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		cmv3.setDescription(VersionEntityTypeEnum.CATEGORY.getDisplayStr());
		VersionView vv3 = new VersionView();
		vv3.setEntityType(VersionEntityTypeEnum.CATEGORY.toString());
		vv3.setEntityId(3L);
		vv3.setVersion(4L);
		cmv3.setVersionView(vv3);
		cmv3.setEntityVersionList(subCatMenuList);
		catMenuList.add(cmv3);

		EntityVersionView cmv4 = new EntityVersionView();
		cmv4.setModule(ModuleEnum.IN_ROOM_DINING.toString());
		cmv4.setDescription(VersionEntityTypeEnum.CATEGORY.getDisplayStr());
		VersionView vv4 = new VersionView();
		vv4.setEntityType(VersionEntityTypeEnum.CATEGORY.toString());
		vv4.setEntityId(4L);
		vv4.setVersion(1L);
		cmv4.setVersionView(vv4);
		cmv4.setEntityVersionList(subCatMenuList);
		catMenuList.add(cmv4);
		
		resp.setEntityVersionList(catMenuList);
		resp.getEntityVersionList().addAll(dummyOtherVersionViewList());
		return resp;
	}
}
